package com.sxg.controller;

import com.sxg.convert.SxgShopConcernConvert;
import com.sxg.entity.SxgShopConcernEntity;
import com.sxg.query.SxgShopConcernQuery;
import com.sxg.vo.SxgShopConcernVO;
import lombok.AllArgsConstructor;
import com.sxg.page.PageResult;
import com.sxg.utils.code.Result;
import com.sxg.service.SxgShopConcernService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 店铺收藏表
*
* @author 浪漫写尽歌谱 3298751420@qq.com
* @since 1.0.0 2024-03-07
*/
@RestController
@RequestMapping("sxg/sxg_shop_concern")
@AllArgsConstructor
public class SxgShopConcernController {
    private final SxgShopConcernService sxgShopConcernService;

    @GetMapping("page")
    @PreAuthorize("hasAuthority('sxg:sxg_shop_concern:page')")
    public Result<PageResult<SxgShopConcernVO>> page(@Valid SxgShopConcernQuery query){
        PageResult<SxgShopConcernVO> page = sxgShopConcernService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @PreAuthorize("hasAuthority('sxg:sxg_shop_concern:info')")
    public Result<SxgShopConcernVO> get(@PathVariable("id") Long id){
        SxgShopConcernEntity entity = sxgShopConcernService.getById(id);

        return Result.ok(SxgShopConcernConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @PreAuthorize("hasAuthority('sxg:sxg_shop_concern:save')")
    public Result<String> save(@RequestBody SxgShopConcernVO vo){
        sxgShopConcernService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @PreAuthorize("hasAuthority('sxg:sxg_shop_concern:update')")
    public Result<String> update(@RequestBody @Valid SxgShopConcernVO vo){
        sxgShopConcernService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @PreAuthorize("hasAuthority('sxg:sxg_shop_concern:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        sxgShopConcernService.delete(idList);

        return Result.ok();
    }
}